using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace TVDesigner.Gui
{
	public partial class DefaultStatusBar : UserControl
	{
		public enum EState
		{
			Idle,
			Error
		}

		public DefaultStatusBar()
		{
			InitializeComponent();
		}


		private EState _State = EState.Idle;
		private int _IsBusy = 0;
		public EState State
		{
			get { return _State; }
		}
		public string Message
		{
			get { return panStatusText.Text; }
		}

		public void DisplayIdleMessage(string message)
		{
			panStatusText.ForeColor = SystemColors.ControlText;
			panErrorIcon.Visible = false;
			panStatusText.Text = message;
			panStatusText.Font = new Font(panStatusText.Font, FontStyle.Regular);
			_State = EState.Idle;
		}
		public void DisplayErrorMessage(string message)
		{
			panStatusText.Text = message;
			panStatusText.ForeColor = Color.Red;
			panStatusText.Font = new Font(panStatusText.Font, FontStyle.Bold);
			panErrorIcon.Visible = true;
			_State = EState.Error;
		}

		public void StartBusy(string message)
		{
			_IsBusy++;
			if(_IsBusy == 1)
			{
				toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
				toolStripProgressBar1.Visible = true;

                panStatusText.ForeColor = SystemColors.ControlText;
                panErrorIcon.Visible = false;
                panStatusText.Text = message;
                panStatusText.Font = new Font(panStatusText.Font, FontStyle.Regular);
			}
		}
		public void EndBusy()
		{
			_IsBusy--;
			if(_IsBusy == 0)
			{
				toolStripProgressBar1.Style = ProgressBarStyle.Continuous;
				toolStripProgressBar1.Visible = false;

                panStatusText.ForeColor = SystemColors.ControlText;
                panErrorIcon.Visible = false;
                panStatusText.Text = string.Empty;
                panStatusText.Font = new Font(panStatusText.Font, FontStyle.Regular);
			}
		}
	}
}
